@extends('layouts.back_stage')
@section('content')
    <link rel="stylesheet" href="{{env('CDN_DOMAIN_NAME')}}/css/createPro.css"/>
    <link rel="stylesheet" href="{{env('CDN_DOMAIN_NAME')}}/css/clothInfo.css"/>
    <style>
        .form_li_surface select{
            float:none;
            margin-right:10px;
        }
        .form_ul_surface table input{
            border:none;
            text-align: center;
        }
        .form_ul_surface table select{
            border:none;
            text-align: center;
        }
        .check_submit li{
            width:100%;
        }
        .check_submit li button{
            float: right;
        }
        .check_submit li h3{
            width:100%;
            text-align: right;
            display: block;
        }
        .form_li span{
            border-bottom:1px solid #ccc;
            padding-left:5px;
        }
    </style>

    <div class="container">
        <div class="row">
            <br>
            <div><h3 >采购确认入库</h3></div>
            <div style="width:90%;margin-left:100px;">
                <br>
                <h4>采购单号:</h4><span class="pur_list_id">{{ $info->plan_code }}</span>
                <hr>
                <div class="form-group">
                    <ul class="form_ul">
                        <li class="form_li" style="width:220px;">供应商：<span>{{ $supplier[$info->supplier] }}</span>
                        </li>
                        <li class="form_li" style="width:200px;">销售季节：<span>{{ $info->season }}</span>
                        </li>
                        <li class="form_li" style="width:220px;" >采购类型：<span>
                                @if( $info->purchase_status == 1)
                                    计划采购
                                    @elseif( $info->purchase_status == 2 )
                                    提前采购
                                @endif
                            </span>
                        </li>

                    </ul>
                    <ul class="form_ul">
                        <li class="form_li" style="width:220px;">合同号：<span>{{ $info->contract_code }}</span>
                        </li>
                        <li class="form_li" style="width:200px;">合同签订人：<span>{{ $info->contract_name }}</span>
                        </li>
                        <li class="form_li" style="width:220px;">备注:<span>{{ $info->remarks }}</span>
                        <span></span></li>
                    </ul>
                    <ul class="form_ul">
                        <li class="form_li" style="width:220px;">总计数量：{{$nums_prices['total_nums']}}<span></span>
                        </li>
                        <li class="form_li" style="width:200px;">总计金额：{{$nums_prices['total_prices']}}<span></span>
                        </li>
                    </ul>
                </div>
                <div style="width:100%;border-bottom: 1px solid #cccccc;height:20px;margin-bottom: 20px;"></div>
                <ul class="form_ul_surface">
                    <table class="pantone" border="1" cellspacing="0" cellpadding="0">
                        <thead>
                        <tr>
                            <td class="col-md-1">面辅料号</td>
                            <td class="col-md-1">颜色</td>
                            <td class="col-md-1">采购量</td>
                            <td class="col-md-1">采购价</td>
                            <td class="col-md-1">金额</td>
                            <td class="col-md-1">实际到库</td>
                            <td class="col-md-1">用于款号</td>
                            <td class="col-md-1">摆放位置</td>
                            <td class="col-md-1">备注</td>
                            <td class="col-md-2">操作</td>
                        </tr>
                        </thead>
                        <tbody>
                        @if(count($details) > 0)
                            @foreach($details as $k=>$v)
                                <tr>
                                    <td class="by_cloth_code">{{ $v->cloth_code }}</td>
                                    <td class="by_color">{{ $v->color }}</td>
                                    <td>{{ $v->purchase }} {{ $v->unit }}</td>
                                    <td>{{ $v->purchase_price }}/{{ $v->unit }}</td>
                                    <td>{{ $v->total_price }}</td>
                                    <td class="by_to_num"><input type="text" class="form-control" value="{{ $v->to_num }}" /></td>
                                    <td>{{ $v->girard }}</td>
                                    <td class="by_cloth_infos"><input type="text" class="form-control" value="{{ $v->cloth_infos }}" /></td>
                                    <td class="by_remarks"><input type="text" class="form-control" value="{{ $v->remarks }}" /></td>
                                    <td><button class="btn btn-success check_stores" id="{{ $v->id }}">确认到库</button></td>
                                </tr>
                                @endforeach
                            @endif
                        </tbody>
                    </table>
                    <li class="form_li" style="width:100%;">
                        <a class="btn btn-info" style="margin-top:15px;float:right;" href="/storage/index">返回上一页</a>
                    </li>
                </ul>
            </div>
        </div>
    </div>

    <script type="text/javascript">
        (function ($) {     //获取URL参数
            $.getUrlParam = function (name) {
                var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
                var r = window.location.search.substr(1).match(reg);
                if (r != null) return unescape(r[2]); return null;
            }
        })(jQuery);
        $('.check_stores').click(function () {
            var getClothCode = $(this).parent().siblings('.by_cloth_code').text();
            var getColor = $(this).parent().siblings('.by_color').text();
            var getToNum = $(this).parent().siblings('.by_to_num').children().val();
            var getClothInfos = $(this).parent().siblings('.by_cloth_infos').children().val();
            var getRemarks = $(this).parent().siblings('.by_remarks').children().val();
            $.ajax({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                },
                url:'/storage/confirm_to_stock',
                type:'post',
                dataType:'json',
                data:{
                    purchase_id:$.getUrlParam('id'),
                    cloth_code:getClothCode,
                    color:getColor,
                    to_num:getToNum,
                    cloth_info:getClothInfos,
                    remarks:getRemarks
                },
                success:function (res) {
                    if(res.success){
                        $(".faceImg").attr("src","/img/laugh.png");
                        $(".oHandle").text("已确认到库");
                        $(".oSuccess").show(0).delay(1000).hide(0);
                    }else{
                        $(".faceImg").attr("src","/img/weep.png");
                        $(".oHandle").text(res.msg);
                        $(".oSuccess").show(0).delay(1000).hide(0);
                    }
                }
            })
        });
    </script>
@endsection